package com.superme.bizclientbyribbon.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2017/6/23.
 */
@Configuration
public class BizserverConfiguration {
    /*
    @Bean
    public OAuth2RestTemplate getOAuth2RestTemplate(OAuth2ClientContext oauth2Context) {

        OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource(),oauth2Context);

        return restTemplate;
    }*/
    @Autowired
    OAuth2ClientContext oauth2Context;

    @Bean
    public RestTemplate getRestTemplate() {

        RestTemplate restTemplate = new RestTemplate();

        return restTemplate;
    }


    @Bean
    @ConfigurationProperties(prefix = "security.oauth2.client")
    public ClientCredentialsResourceDetails clientCredentialsResourceDetails() {
        ClientCredentialsResourceDetails ccr =  new ClientCredentialsResourceDetails();

        return ccr;
    }


    @Primary
    @LoadBalanced
    @Bean
    public OAuth2RestTemplate clientCredentialsRestTemplate() {
        return new OAuth2RestTemplate(clientCredentialsResourceDetails(),oauth2Context);
    }





}
